/**
 * Created by hejg on 2018/5/30.
 */
import React, {Component} from 'react';
import {
    Text, View,
} from 'react-native';

export class ErrorBoundary extends Component {
    constructor(props) {
        super(props);
        this.state = {hasError: false};
    }

    componentDidCatch(error, info) {
        // Display fallback UI
        this.setState({hasError: true});
        // You can also log the error to an error reporting service
        // logErrorToMyService(error, info);
    }

    render() {
        if (this.state.hasError) {
            // You can render any custom fallback UI
            return <Text>Something went wrong.</Text>;
        }
        return <View>{this.props.children}</View>
    }
}